﻿using StarLabel.label.item;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml;

namespace StarLabel.label.item
{
    /// <summary>
    /// Copyright 2019  ZhengJi. All Rights Reserved.
    ///  档案题名
    /// </summary>
    [Obsolete("ArchTitleItem 过期,使用 SplitByWordItem")]
    public class ArchTitleItem : TextItem
    {
        public int WordsPerColumn { get; set; }
        public float OffsetX { get; set; }
        public float OffsetY { get; set; }
        public float NumberOffsetX { get; set; }

        public int NumberRotation { get; set; }
        
        public ArchTitleItem(XmlElement el) : base(el)
        {
        }
        protected override void parseFromXml()
        {
            this.WordsPerColumn = this.xmlEl.Attributes["WordsPerColumn"] == null ? 50 : int.Parse(this.xmlEl.Attributes["WordsPerColumn"].Value);

            this.OffsetX = this.xmlEl.Attributes["OffsetX"] == null ? 50 : float.Parse(this.xmlEl.Attributes["OffsetX"].Value);

            this.OffsetY = this.xmlEl.Attributes["OffsetY"] == null ? 50 : float.Parse(this.xmlEl.Attributes["OffsetY"].Value);

            this.NumberOffsetX = this.xmlEl.Attributes["NumberOffsetX"] == null ? -30 : float.Parse(this.xmlEl.Attributes["NumberOffsetX"].Value);

            this.NumberRotation = this.xmlEl.Attributes["NumberRotation"] == null ? 90 : int.Parse(this.xmlEl.Attributes["NumberRotation"].Value);

            base.parseFromXml();
        }

        public override void DrawLabel(float x, float y, string labelText,string rotation)
        {
            char[] words = labelText.ToArray();

            int iCount = 1;
            //string ro = this.Rotation;
        
            if (words.Length< this.WordsPerColumn)
            {
                x = x - this.OffsetX;
            }

            float tempX = x;
            float tempY = y;

            foreach (char w in words)
            {
               // float fltR = float.Parse(ro);
                if (!Regex.IsMatch(w.ToString(), "[\\u4e00-\\u9fbb]+$"))
                {
                    // fltR = fltR + 90;
                    

                    //this.Rotation = NumberRotation.ToString();// fltR.ToString();
                    float x2 = x + NumberOffsetX;
                    base.DrawLabel(x2, y, w.ToString(), NumberRotation.ToString());
                }
                else
                {
                   // this.Rotation =ro;
                    base.DrawLabel(x, y, w.ToString(),this.Rotation);
                }
               

                y = y - float.Parse(this.FontHeight)- OffsetY;

                if (iCount % this.WordsPerColumn==0)
                {
                    x = x - OffsetX;
                    y = tempY;
                }
                iCount++;

            }
            
        }
    }
}
